package com.shtel.paas.monitorcenter.miroservice.management.controller;

import com.shtel.paas.monitorcenter.asset.management.entity.HostListEntity;
import com.shtel.paas.monitorcenter.miroservice.management.entity.MiroServiceEntity;
import com.shtel.paas.monitorcenter.miroservice.management.service.MiroServiceDataService;
import com.shtel.paas.monitorcenter.util.Page;
import org.apache.commons.lang.StringUtils;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName
 * @Description Too
 * @Author zhoujie
 * @Data 2018/07/18 13:55
 **/
@MapperScan("com.shtel.paas.monitorcenter.miroservice.management.mapper")

@RestController
public class MiroServiceCollectingController {

    @Autowired
    private MiroServiceDataService miroServiceDataService;

    @RequestMapping(value="/selectMiroService")
    public Page<MiroServiceEntity> selectMiroServiceList(@RequestParam("miroservice")String miroservice,
                                                         @RequestParam("page")String page,
                                                         @RequestParam("size")String size){
        Page<MiroServiceEntity> pageContent = miroServiceDataService.selectMicroServiceInfo(miroservice,(StringUtils.isBlank(page)?0:Integer.parseInt(page)),(StringUtils.isBlank(size)?0:Integer.parseInt(size)));

        return pageContent;
    }

    @RequestMapping(value="/insertMiroService")
    public int insertMiroServiceList(@RequestParam("id")String id,
                                     @RequestParam("miroservice")String miroservice,
                                     @RequestParam("namespace")String namespace,
                                     @RequestParam("containerName")String containerName,
                                     @RequestParam("service")String service,
                                     @RequestParam("hostid")String hostid,
                                     @RequestParam("port")String port,
                                     @RequestParam("podName")String podName ){
        MiroServiceEntity miroServiceEntity = new MiroServiceEntity();
       // miroServiceEntity.setId(Integer.parseInt(id));
        miroServiceEntity.setMiroservice(miroservice);
        miroServiceEntity.setNamespace(namespace);
        miroServiceEntity.setContainerName(containerName);
        miroServiceEntity.setService(service);
        miroServiceEntity.setHostid(hostid);
        miroServiceEntity.setPort(port);
        miroServiceEntity.setPodName(podName);
      //  miroServiceEntity.setIp(ip);
        int i = miroServiceDataService.insertMicroServiceInfo(miroServiceEntity);
        return i;
    }

    @RequestMapping(value = "/updateMiroService")
    public int updateMiroServiceList(@RequestParam("id")String id,
                                     @RequestParam("miroservice")String miroservice,
                                     @RequestParam("namespace")String namespace,
                                     @RequestParam("containerName")String containerName,
                                     @RequestParam("service")String service,
                                     @RequestParam("hostid")String hostid,
                                     @RequestParam("port")String port,
                                     @RequestParam("podName")String podName){
        MiroServiceEntity miroServiceEntity = new MiroServiceEntity();
        miroServiceEntity.setId(Integer.parseInt(id));
        miroServiceEntity.setMiroservice(miroservice);
        miroServiceEntity.setNamespace(namespace);
        miroServiceEntity.setContainerName(containerName);
        miroServiceEntity.setService(service);
        miroServiceEntity.setHostid(hostid);
        miroServiceEntity.setPort(port);
        miroServiceEntity.setPodName(podName);
        //miroServiceEntity.setIp(ip);
        int i = miroServiceDataService.updateMicroServiceInfo(miroServiceEntity);
        return i;
    }

    @RequestMapping(value="/deleteMiroService")
    public  int deleteMiroServiceList(@RequestParam("id")String id,
                                      @RequestParam("miroservice")String miroservice,
                                      @RequestParam("namespace")String namespace,
                                      @RequestParam("containerName")String containerName,
                                      @RequestParam("service")String service,
                                      @RequestParam("hostid")String hostid,
                                      @RequestParam("port")String port,
                                      @RequestParam("podName")String podName){
        MiroServiceEntity miroServiceEntity = new MiroServiceEntity();
        miroServiceEntity.setId(Integer.parseInt(id));
        miroServiceEntity.setMiroservice(miroservice);
        miroServiceEntity.setNamespace(namespace);
        miroServiceEntity.setContainerName(containerName);
        miroServiceEntity.setService(service);
        miroServiceEntity.setHostid(hostid);
        miroServiceEntity.setPort(port);
        miroServiceEntity.setPodName(podName);
      //  miroServiceEntity.setIp(ip);
        int i = miroServiceDataService.deleteMicroServiceInfo(miroServiceEntity);
        return i;
    }
}
